home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / protocols / tests / checks.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  17KB  |  472 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. __all__ = [
  5.     'TestBase',
  6.     'ImplementationChecks',
  7.     'ProviderChecks',
  8.     'InstanceImplementationChecks',
  9.     'makeClassTests',
  10.     'ClassProvidesChecks',
  11.     'AdaptiveChecks',
  12.     'SimpleAdaptiveChecks',
  13.     'makeMetaClassProvidesTests',
  14.     'BasicClassProvidesChecks']
  15. from unittest import TestCase, makeSuite, TestSuite
  16. from protocols import *
  17.  
  18. def a1(ob):
  19.     return ('a1', ob)
  20.  
  21.  
  22. def a2(ob):
  23.     return ('a2', ob)
  24.  
  25.  
  26. class TestBase(TestCase):
  27.     a1 = staticmethod(a1)
  28.     a2 = staticmethod(a2)
  29.     
  30.     def assertObProvidesOnlyA(self):
  31.         pass
  32.  
  33.     
  34.     def assertObProvidesAandB(self):
  35.         pass
  36.  
  37.     
  38.     def assertAmbiguous(self, a1, a2, d1, d2, ifaces):
  39.         
  40.         try:
  41.             self.declareObAdapts(a2, ifaces)
  42.         except TypeError:
  43.             v = None
  44.  
  45.  
  46.     
  47.     def make(self, klass):
  48.         return klass()
  49.  
  50.     
  51.     def assertObProvidesSubsetOfA(self):
  52.         
  53.         class IC((self.Interface,)):
  54.             advise(protocolIsSubsetOf = [
  55.                 self.IA])
  56.             if 'self' in locals():
  57.                 del locals()['self']
  58.             
  59.  
  60.  
  61.     
  62.     def setupBases(self, base):
  63.         
  64.         class M1(base):
  65.             pass
  66.  
  67.         
  68.         class M2(base):
  69.             pass
  70.  
  71.         return (M1, M2)
  72.  
  73.     
  74.     def assertM1ProvidesOnlyAandM2ProvidesB(self, M1, M2):
  75.         pass
  76.  
  77.     
  78.     def assertChangingBasesChangesInterface(self, M1, M2, m1, m2):
  79.         
  80.         try:
  81.             M1.__bases__ = (M2,)
  82.         except TypeError:
  83.             pass
  84.  
  85.  
  86.     
  87.     def assertObProvidesABCD(self, IC, ID):
  88.         pass
  89.  
  90.     
  91.     def assertObProvidesCandDnotAorB(self, IC, ID):
  92.         pass
  93.  
  94.  
  95.  
  96. class ProviderChecks(TestBase):
  97.     
  98.     def declareObImplements(self, ifaces):
  99.         adviseObject(self.ob, provides = ifaces)
  100.  
  101.     
  102.     def declareObAdapts(self, factory, ifaces):
  103.         declareAdapter(factory, provides = ifaces, forObjects = [
  104.             self.ob])
  105.  
  106.     
  107.     def checkSimpleRegister(self):
  108.         self.declareObImplements([
  109.             self.IA])
  110.         self.assertObProvidesOnlyA()
  111.  
  112.     
  113.     def checkImpliedRegister(self):
  114.         self.declareObImplements([
  115.             self.IB])
  116.         self.assertObProvidesAandB()
  117.  
  118.  
  119.  
  120. class SimpleAdaptiveChecks:
  121.     
  122.     def checkDelayedImplication(self):
  123.         self.declareObImplements([
  124.             self.IA])
  125.         self.assertObProvidesSubsetOfA()
  126.  
  127.     
  128.     def checkIndirectImplication(self):
  129.         
  130.         class IC(self.Interface):
  131.             pass
  132.  
  133.         
  134.         class ID(IC):
  135.             pass
  136.  
  137.         self.declareObImplements([
  138.             ID])
  139.         self.assertObProvidesCandDnotAorB(IC, ID)
  140.         declareAdapter(NO_ADAPTER_NEEDED, provides = [
  141.             self.IB], forProtocols = [
  142.             IC])
  143.         self.assertObProvidesABCD(IC, ID)
  144.  
  145.  
  146.  
  147. class AdaptiveChecks(SimpleAdaptiveChecks):
  148.     
  149.     def checkAmbiguity(self):
  150.         self.declareObAdapts(self.a1, [
  151.             self.IA])
  152.         self.assertAmbiguous(self.a1, self.a2, 1, 1, [
  153.             self.IA])
  154.  
  155.     
  156.     def checkOverrideDepth(self):
  157.         self.declareObAdapts(self.a1, [
  158.             self.IB])
  159.         self.assertEquals(self.IA(self.ob, None), ('a1', self.ob))
  160.         self.declareObAdapts(self.a2, [
  161.             self.IA])
  162.         self.assertEquals(self.IA(self.ob, None), ('a2', self.ob))
  163.  
  164.     
  165.     def checkComposed(self):
  166.         
  167.         class IC(self.Interface):
  168.             pass
  169.  
  170.         declareAdapter(self.a2, provides = [
  171.             IC], forProtocols = [
  172.             self.IA])
  173.         self.declareObAdapts(self.a1, [
  174.             self.IA])
  175.         self.assertEqual(IC(self.ob, None), ('a2', ('a1', self.ob)))
  176.  
  177.     
  178.     def checkLateDefinition(self):
  179.         self.declareObAdapts(DOES_NOT_SUPPORT, [
  180.             self.IA])
  181.         self.declareObImplements([
  182.             self.IA])
  183.         self.declareObAdapts(DOES_NOT_SUPPORT, [
  184.             self.IA])
  185.  
  186.  
  187.  
  188. class InstanceImplementationChecks(TestBase):
  189.     
  190.     def declareObImplements(self, ifaces):
  191.         declareImplementation(self.klass, ifaces)
  192.  
  193.     
  194.     def declareObAdapts(self, factory, ifaces):
  195.         declareAdapter(factory, provides = ifaces, forTypes = [
  196.             self.klass])
  197.  
  198.     
  199.     def checkSimpleRegister(self):
  200.         self.declareObImplements([
  201.             self.IA])
  202.         self.assertObProvidesOnlyA()
  203.  
  204.     
  205.     def checkImpliedRegister(self):
  206.         self.declareObImplements([
  207.             self.IB])
  208.         self.assertObProvidesAandB()
  209.  
  210.  
  211.  
  212. class ImplementationChecks(InstanceImplementationChecks):
  213.     
  214.     def checkNoClassPassThru(self):
  215.         self.declareObImplements([
  216.             self.IA])
  217.  
  218.     
  219.     def checkInheritedDeclaration(self):
  220.         self.declareObImplements([
  221.             self.IB])
  222.         
  223.         class Sub(self.klass):
  224.             pass
  225.  
  226.         inst = self.make(Sub)
  227.  
  228.     
  229.     def checkRejectInheritanceAndReplace(self):
  230.         self.declareObImplements([
  231.             self.IB])
  232.         
  233.         class Sub((self.klass,)):
  234.             advise(instancesDoNotProvide = [
  235.                 self.IB])
  236.  
  237.         inst = self.make(Sub)
  238.         declareImplementation(Sub, instancesProvide = [
  239.             self.IB])
  240.  
  241.  
  242.  
  243. class BasicClassProvidesChecks:
  244.     
  245.     def checkNoInstancePassThru(self):
  246.         inst = self.ob()
  247.         adviseObject(self.ob, provides = [
  248.             self.IA])
  249.  
  250.     
  251.     def checkChangingBases(self):
  252.         (M1, M2) = self.setupBases(self.ob)
  253.         adviseObject(M1, provides = [
  254.             self.IA])
  255.         adviseObject(M2, provides = [
  256.             self.IB])
  257.         self.assertM1ProvidesOnlyAandM2ProvidesB(M1, M2)
  258.         self.assertChangingBasesChangesInterface(M1, M2, M1, M2)
  259.  
  260.  
  261.  
  262. class ClassProvidesChecks(BasicClassProvidesChecks):
  263.     
  264.     def checkInheritedDeclaration(self):
  265.         
  266.         class Sub(self.ob):
  267.             pass
  268.  
  269.         adviseObject(self.ob, provides = [
  270.             self.IB])
  271.  
  272.     
  273.     def checkRejectInheritanceAndReplace(self):
  274.         adviseObject(self.ob, provides = [
  275.             self.IB])
  276.         
  277.         class Sub((self.ob,)):
  278.             advise(classDoesNotProvide = [
  279.                 self.IB])
  280.  
  281.         adviseObject(Sub, provides = [
  282.             self.IB])
  283.  
  284.  
  285.  
  286. def makeInstanceTests(base, Picklable, NewStyle):
  287.     
  288.     class AdviseFunction((base,)):
  289.         __module__ = base.__module__
  290.         
  291.         def setUp(self):
  292.             
  293.             def aFunc(foo, bar):
  294.                 pass
  295.  
  296.             self.ob = aFunc
  297.  
  298.  
  299.     AdviseFunction.__name__ = base.__name__ + '.AdviseFunction'
  300.     
  301.     class AdviseModule((base,)):
  302.         __module__ = base.__module__
  303.         
  304.         def setUp(self):
  305.             ModuleType = ModuleType
  306.             import types
  307.             self.ob = ModuleType('x')
  308.  
  309.  
  310.     AdviseModule.__name__ = base.__name__ + '.AdviseModule'
  311.     
  312.     class AdviseInstance('AdviseInstance', (base,)):
  313.         __module__ = base.__module__
  314.         
  315.         def setUp(self):
  316.             self.ob = Picklable()
  317.  
  318.         
  319.         def checkPickling(self):
  320.             loads = loads
  321.             dumps = dumps
  322.             import cPickle
  323.             adviseObject(self.ob, provides = [
  324.                 self.IPure])
  325.             newOb = loads(dumps(self.ob))
  326.  
  327.  
  328.     AdviseInstance.__name__ = base.__name__ + '.AdviseInstance'
  329.     
  330.     class AdviseNewInstance('AdviseNewInstance', (AdviseInstance,)):
  331.         __module__ = base.__module__
  332.         
  333.         def setUp(self):
  334.             self.ob = NewStyle()
  335.  
  336.  
  337.     AdviseNewInstance.__name__ = base.__name__ + '.AdviseNewInstance'
  338.     return (AdviseFunction, AdviseModule, AdviseInstance, AdviseNewInstance)
  339.  
  340.  
  341. def makeClassProvidesTests(base):
  342.     
  343.     class AdviseClass(base):
  344.         
  345.         def setUp(self):
  346.             
  347.             class Classic:
  348.                 pass
  349.  
  350.             self.ob = Classic
  351.  
  352.  
  353.     
  354.     class AdviseType(AdviseClass):
  355.         
  356.         def setUp(self):
  357.             
  358.             class Class(object):
  359.                 pass
  360.  
  361.             self.ob = Class
  362.  
  363.  
  364.     return (AdviseClass, AdviseType)
  365.  
  366.  
  367. def makeMetaClassProvidesTests(base):
  368.     
  369.     class AdviseMixinClass(base):
  370.         
  371.         def setUp(self):
  372.             
  373.             class Meta(ProviderMixin, type):
  374.                 pass
  375.  
  376.             
  377.             class Test((object,)):
  378.                 __metaclass__ = Meta
  379.  
  380.             self.ob = Test
  381.  
  382.  
  383.     
  384.     class AdviseMixinMultiMeta2(base):
  385.         
  386.         def setUp(self):
  387.             
  388.             class Meta(ProviderMixin, type):
  389.                 pass
  390.  
  391.             
  392.             class Test((ProviderMixin, object)):
  393.                 __metaclass__ = Meta
  394.  
  395.             self.ob = Test
  396.  
  397.  
  398.     return (AdviseMixinClass, AdviseMixinMultiMeta2)
  399.  
  400.  
  401. def makeClassTests(base):
  402.     
  403.     class TestClassic((base,)):
  404.         __module__ = base.__module__
  405.         
  406.         def setUp(self):
  407.             
  408.             class Classic:
  409.                 pass
  410.  
  411.             self.klass = Classic
  412.             self.ob = Classic()
  413.  
  414.  
  415.     TestClassic.__name__ = base.__name__ + '.TestClassic'
  416.     
  417.     class TestBuiltin((base,)):
  418.         __module__ = base.__module__
  419.         
  420.         def setUp(self):
  421.             
  422.             class Newstyle(list):
  423.                 __slots__ = ()
  424.  
  425.             self.klass = Newstyle
  426.             self.ob = Newstyle()
  427.  
  428.  
  429.     TestBuiltin.__name__ = base.__name__ + '.TestBuiltin'
  430.     
  431.     class TestMetaclass((base,)):
  432.         __module__ = base.__module__
  433.         
  434.         def setUp(self):
  435.             
  436.             class Meta(type):
  437.                 pass
  438.  
  439.             self.klass = Meta
  440.             
  441.             class Base((object,)):
  442.                 __metaclass__ = Meta
  443.  
  444.             self.ob = Base
  445.  
  446.         
  447.         def make(self, klass):
  448.             return klass('Dummy', (object,), { })
  449.  
  450.  
  451.     TestMetaclass.__name__ = base.__name__ + '.TestMetaclass'
  452.     
  453.     class TestMetaInstance((base,)):
  454.         __module__ = base.__module__
  455.         
  456.         def setUp(self):
  457.             
  458.             class Meta(type):
  459.                 pass
  460.  
  461.             
  462.             class Base((object,)):
  463.                 __metaclass__ = Meta
  464.  
  465.             self.klass = Base
  466.             self.ob = Base()
  467.  
  468.  
  469.     TestMetaInstance.__name__ = base.__name__ + '.TestMetaInstance'
  470.     return (TestClassic, TestBuiltin, TestMetaclass, TestMetaInstance)
  471.  
  472.